<?php

namespace App\Common\WX\App\dev;


use App\Common\Log;
use App\Common\Sys;
use App\Common\WX\App\WxAppBase;
use App\Common\WX\WxWord;
use App\X\EHelper;
use XWX\Common\H;

class text extends WxAppBase
{
    function funcHandle(WxWord $word, $wx_from)
    {
        Log::funcLogDebug(__METHOD__);


        $pwd = EHelper::funcGetConf("SYS.oauth_dev_pwd");
        if ($word->keyNum() == $pwd)
        {
            Log::funcLogDebug(__METHOD__, "授权调试密码：正确");


            $ex_s = 10 * 60; //10分钟过期

            //没值，获取新的，有值拿回原来的
            $dev_code = $this->context()->redis()->get(Sys::getOauthDevKey());
            if ($dev_code == null)
            {
                $dev_code = H::now()->timestamp;
            }
            $this->context()->redis()->setEx(Sys::getOauthDevKey(), $ex_s, $dev_code);


            $content = "dev_code:{$dev_code}" . PHP_EOL;
            $content .= "expire_time:" . H::now()->addSecond($ex_s)->toDateTimeString();
            $official_account = $this->getOfficialAccount();
            $official_account->msg48()->funcSendText($wx_from, $content);
        }
    }
}